import pytest
import requests

from api.open_account_api import OpenAccountApi
from api.reg_login_api import RegLoginApi
from common.utils import common_assert, html_util


class TestOpenAccount(object):

    def setup(self) :
        # 创建session对象
        self.ses =requests.session()
        # 实例化封装接口请求的类
        self.reg_login_api = RegLoginApi(self.ses)
        self.open_account_api =OpenAccountApi(self.ses)

    def teardown(self):
        # 关闭session对象
        self.ses.close()

    # 实名认证测试用例
    def test01_realname(self):
        # 实现登录接口
        self.reg_login_api.user_login("13816547004","qqq123")
        # 实现实名认证接口
        resp = self.open_account_api.realname("张三","450102199003078798")

        # 断言
        common_assert(resp, 200, 200, "成功")


    # 开户测试用例
    def test02_open_account(self):
        # 实现登录接口
        self.reg_login_api.user_login("13816547004", "qqq123")
        # 实现开户接口
        resp = self.open_account_api.open_account()
        # 断言
        common_assert(resp, 200, 200, "form")

    # 第三方开户测试用例
    def test03_third_open_account(self):
        # 实现登录接口
        self.reg_login_api.user_login("13816547004", "qqq123")
        # 实现开户接口
        resp1 = self.open_account_api.open_account()
        result = html_util(resp1)
        url = result[0]
        form_dict = result[1]
        # 实现第三方开户接口
        resp2 =self.open_account_api.third_open_account(url,form_dict)
        # 断言
        assert 200==resp2.status_code
        assert "ok" in resp2.text.lower()#将结果装化成小写
        assert "OK" in resp2.text

